home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / pvm34b3.zip / pvm34b3 / pvm3 / gexamples / gs.c < prev    next >
C/C++ Source or Header  |  1997-07-22  |  2KB  |  88 lines

  1.  
  2. static char rcsid[] =
  3.     "$Id: gs.c,v 1.2 1997/07/09 13:27:58 pvmsrc Exp $";
  4.  
  5. /*
  6.  *         PVM version 3.4:  Parallel Virtual Machine System
  7.  *               University of Tennessee, Knoxville TN.
  8.  *           Oak Ridge National Laboratory, Oak Ridge TN.
  9.  *                   Emory University, Atlanta GA.
  10.  *      Authors:  J. J. Dongarra, G. E. Fagg, M. Fischer
  11.  *          G. A. Geist, J. A. Kohl, R. J. Manchek, P. Mucci,
  12.  *         P. M. Papadopoulos, S. L. Scott, and V. S. Sunderam
  13.  *                   (C) 1997 All Rights Reserved
  14.  *
  15.  *                              NOTICE
  16.  *
  17.  * Permission to use, copy, modify, and distribute this software and
  18.  * its documentation for any purpose and without fee is hereby granted
  19.  * provided that the above copyright notice appear in all copies and
  20.  * that both the copyright notice and this permission notice appear in
  21.  * supporting documentation.
  22.  *
  23.  * Neither the Institutions (Emory University, Oak Ridge National
  24.  * Laboratory, and University of Tennessee) nor the Authors make any
  25.  * representations about the suitability of this software for any
  26.  * purpose.  This software is provided ``as is'' without express or
  27.  * implied warranty.
  28.  *
  29.  * PVM version 3 was funded in part by the U.S. Department of Energy,
  30.  * the National Science Foundation and the State of Tennessee.
  31.  */
  32.  
  33. /*
  34.     Using pvm_gsize()
  35. */
  36.  
  37. #include <stdio.h>
  38. #include "pvm3.h"
  39.  
  40. int
  41. main(argc, argv)
  42. int argc;
  43. char *argv[];
  44. {
  45.     int mytid, mygid, ctid[32];
  46.     int nproc, i;
  47.  
  48.     mytid = pvm_mytid();
  49.     fprintf(stderr, "%s 0x%x enrolled\n", argv[0], mytid);
  50.     if (mytid < 0) {
  51.         pvm_perror(argv[0]);
  52.         return -1;
  53.         }
  54.  
  55.     if (argc != 2) goto usage;
  56.     if ((nproc = atoi(argv[1])) < 1) goto usage;
  57.     if (nproc > 32) goto usage;
  58.  
  59.     /* join a group */
  60.     mygid = pvm_joingroup(argv[0]);
  61.  
  62.     /* if I'm the first to join then start the others */
  63.     if (mygid == 0) {
  64.         /* start a bunch of children */
  65.         pvm_spawn(argv[0], argv+1, 0, "", nproc-1, ctid);
  66.         /* check them */
  67.         for (i = 0; i < nproc-1; i++)
  68.             fprintf(stderr, "0x%x\n", ctid[i]);
  69.         }
  70.  
  71.     while(pvm_gsize(argv[0]) < nproc)
  72.         if (mygid == 0)
  73.             fputs("waiting on kids to join\n", stderr);
  74.  
  75.     /* sync */
  76.     pvm_barrier(argv[0], nproc);
  77.  
  78.     /* leave the group */
  79.     if(pvm_lvgroup(argv[0]) < 0)
  80.             pvm_perror(argv[0]);
  81.  
  82.     pvm_exit();
  83.     return 0;
  84. usage:
  85.     fprintf(stderr, "usage: %s <nproc>\n", argv[0]);
  86.     return -1;
  87. }
  88.